unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, FileCtrl, ExtCtrls, OggVorbis;

type
  TMainForm = class(TForm)
    DriveList: TDriveComboBox;
    FolderList: TDirectoryListBox;
    FileList: TFileListBox;
    CloseButton: TButton;
    InfoBevel: TBevel;
    IconImage: TImage;
    ValidHeaderLabel: TLabel;
    FileSizeLabel: TLabel;
    ValidHeaderText: TEdit;
    SampleRateText: TEdit;
    ChannelModeLabel: TLabel;
    BitRateLabel: TLabel;
    SampleRateLabel: TLabel;
    BitRateText: TEdit;
    ChannelModeText: TEdit;
    FileSizeText: TEdit;
    DurationText: TEdit;
    DurationLabel: TLabel;
    TitleText: TEdit;
    CommentText: TEdit;
    ArtistText: TEdit;
    TrackText: TEdit;
    AlbumText: TEdit;
    TitleLabel: TLabel;
    CommentLabel: TLabel;
    ArtistLabel: TLabel;
    TrackLabel: TLabel;
    AlbumLabel: TLabel;
    DateText: TEdit;
    DateLabel: TLabel;
    GenreLabel: TLabel;
    GenreText: TEdit;
    VendorLabel: TLabel;
    VendorText: TEdit;
    procedure CloseButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FileListChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    Vorbis: TOggVorbis;
    procedure ClearAll;
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.ClearAll;
begin
  { Clear all captions }
  ValidHeaderText.Text := '';
  FileSizeText.Text := '';
  ChannelModeText.Text := '';
  SampleRateText.Text := '';
  DurationText.Text := '';
  BitRateText.Text := '';
  TitleText.Text := '';
  ArtistText.Text := '';
  AlbumText.Text := '';
  TrackText.Text := '';
  DateText.Text := '';
  GenreText.Text := '';
  CommentText.Text := '';
  VendorText.Text := '';
end;

procedure TMainForm.CloseButtonClick(Sender: TObject);
begin
  { Exit }
  Close;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  { Create object and clear captions }
  Vorbis := TOggVorbis.Create;
  ClearAll;
end;

procedure TMainForm.FileListChange(Sender: TObject);
begin
  { Clear captions }
  ClearAll;
  if FileList.FileName = '' then exit;
  if FileExists(FileList.FileName) then
    { Load OggVorbis header data }
    if Vorbis.ReadFromFile(FileList.FileName) then
      if Vorbis.Valid then
      begin
        { Fill captions }
        ValidHeaderText.Text := 'Yes';
        if Vorbis.Corrupted then
          ValidHeaderText.Text := ValidHeaderText.Text + ' (file corrupted)';
        FileSizeText.Text := IntToStr(Vorbis.FileSize) + ' bytes';
        ChannelModeText.Text := Vorbis.ChannelMode;
        SampleRateText.Text := IntToStr(Vorbis.SampleRate) + ' hz';
        DurationText.Text := FormatFloat('.000', Vorbis.Duration) + ' sec.';
        BitRateText.Text := IntToStr(Vorbis.BitRate) + ' kbit';
        TitleText.Text := Vorbis.Title;
        ArtistText.Text := Vorbis.Artist;
        AlbumText.Text := Vorbis.Album;
        if Vorbis.Track > 0 then TrackText.Text := IntToStr(Vorbis.Track);
        DateText.Text := Vorbis.Date;
        GenreText.Text := Vorbis.Genre;
        CommentText.Text := Vorbis.Comment;
        VendorText.Text := Vorbis.Vendor;
      end
      else
        { Header not found }
        ValidHeaderText.Text := 'No'
    else
      { Read error }
      ShowMessage('Can not read header in the file: ' + FileList.FileName)
  else
    { File does not exist }
    ShowMessage('The file does not exist: ' + FileList.FileName);
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  { Free memory }
  Vorbis.Free;
end;

end.
